#include <iostream>
#include <algorithm>
#define maxn 1005
using namespace std;
int r, map[maxn][maxn], f[maxn][maxn];
int main()
{
    cin >> r;
    for (int i = 1; i <= r; ++i)
    {
        for (int j = 1; j <= i; ++j)
        {
            cin >> map[i][j];
        }
    }
    for (int i = r + 1; i >= 1; i--)
    {
        for (int j = 1; j <= i; ++j)
        {
            f[i][j] = map[i][j] + max(f[i + 1][j], f[i + 1][j + 1]);
        }
    }
    cout << f[1][1] << endl;
    return 0;
}